home *** CD-ROM | disk | FTP | other *** search
- Path: zeus.rbi.informatik.uni-frankfurt.de!gna1pc
- From: Ferber@zoology.uni-frankfurt.de (Michael Ferber)
- Newsgroups: comp.lang.c
- Subject: performance of fread
- Date: Mon, 22 Jan 96 08:36:57 GMT
- Organization: Uni Frankfurt
- Message-ID: <4eaecp$m5a@zeus.rbi.informatik.uni-frankfurt.de>
- NNTP-Posting-Host: gna1pc.zoologys.uni-frankfurt.de
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- I have a file containing data (integers) which are arranged in the following
- way:
- a1, b1, c1, d1, a2, b2, c2, d2, a3, b3 ........, dn
-
- For further processing I have to put these data into arrays like:
-
- a1, a2, .... an
- b1, b2, .... bn
-
- or a twodimensional array like:
-
- X[4][n]
-
- I think there are several ways to do this.
- 1. To read each integer and put it into the appropriate array, and the read
- the next value. This assumes that I have call fread d * n times. Due to the
- fact that I have to read many (several thousand) integers this seems to be
- slow but easy to implement.
- 2. To read many integers into a buffer. And then copy the integers to their
- appropriate arrays. This seems to be faster, but more difficult to control
- compared with 3 and 1, because I always have to check if a new read is
- necessary while processing the data within the array.
- 3. To use the approach described in 1. but with a large buffer set with
- setvbuf.
- Furthermore I cannot read all the data of the file in a single turn because a
- single file may contain a theoretically unlimited number of integers, usually
- my files contain about 12 - 15 million points.
-
- My question: How time consuming is the overhead of calling fread reading from
- a large buffer compared to a for( ) loop which takes his data from a memory
- block which was filled by a single call of fread.
-
- Any suggestions?
-
- Thanks in advance
- Michael
-
- ------------------------------------------------------------------------------------
- || Dr. Michael Ferber ||
- || Universitaet Frankfurt ||"science moves,
- || Zoologisches Institut || but slowly, slowly ......"
- || email: Ferber@zoology.uni-frankfurt.de || Tennyson
- ------------------------------------------------------------------------------------
-